package cn.marinda.spritefragment.data;

import org.bukkit.Material;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;

import java.security.Key;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class ConfigData implements DataInterface{
    /*
    配置文件信息
     */
    private Configuration config = null;
    private String prefix;
    private boolean vaule;
    private String invName;
    private Set<String> key = null;
    private Map<String,String> mark = null;
    private ConfigurationSection cs = null;

    //configData
    public ConfigData(Plugin plugin){
        config = plugin.getConfig();
        key = new HashSet<>();
        mark = new HashMap<>();
        DefaultConfig();
    }
    //获取config
    public Configuration getConfig(){
        return config;
    }

    //初始化
    public void DefaultConfig(){
        setPrefix(getConfig().getString("prefix"));
        setVaule(getConfig().getBoolean("vault"));
        setInvName(getConfig().getString("invTitle"));
        cs = getConfig().getConfigurationSection("craftItems");
        key =cs.getKeys(false);
        for(String keyName:key){
            putMark(keyName,getConfig().getString(cs.getName() + "." + keyName+".resultItem"));
        }
    }

    public Set<String> getKey() {
        return key;
    }

    public Map<String, String> getMark() {
        return mark;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public boolean isVaule() {
        return vaule;
    }

    public void setVaule(boolean vaule) {
        this.vaule = vaule;
    }

    public String getInvName() {
        return invName;
    }

    public void setInvName(String invName) {
        this.invName = invName;
    }

    public void putMark(String keyName,String markName){
        if(!getMark().containsKey(keyName)){
            getMark().put(keyName,markName);
        }
    }


    @Override
    public Set<String> getKeys() {
        return getKey();
    }

    @Override
    public ItemStack getResultItems(String key) {
        return null;
    }

    @Override
    public ItemStack getItems(String key) {
        return null;
    }

    @Override
    public int getItemPayNumber(String key) {
        return 0;
    }

    @Override
    public String getKeyMark(int index,String parrentName) {
        return null;
    }

    @Override
    public int getNumber(int index, String parrentKey) {
        return 0;
    }


    @Override
    public String getExchangeResule(String key) {
        ExchangeConfig ex = new ExchangeConfig();
            if(ex.getKeys().contains(key)){
                return getMark().get(key);
            }
        return null;
    }

}
